import {createRenderer} from 'vue'
import {Container, Graphics} from "pixi.js";

const renderer = createRenderer({
    createElement(type){
        let element;
        switch (type) {
            case "container":
                element = new Container();
                break;
            case "circle":
                element = new Graphics();
                element.beginFill(0xCD7F32)
                element.drawCircle(50,50,50)
                element.endFill()
                break;
            case "rect":
                element = new Graphics();
                element.beginFill(0xCD7F32)
                element.drawRect(50,50,50,50)
                element.endFill()
                break;
        }

        return element;
    },
    insert(el,parent){
        if(el){
            parent.addChild(el)
        }
    },
    parentNode(node){
        return node.parent;
    },
    remove(el) {
        // 删除一个元素的时候 会进行调用
        if (el && el.parent) {
            el.parent.removeChild(el);
        }
    },
    patchProp(el,key,prevValue,newValue){
        switch (key){
            case "onClick":
                el.on('pointertap',newValue)
                break
            default:
                el[key] = newValue;
                break
        }
    },
    nextSibling(){},
    createComment(){},
})

export function createApp(rootComponent){
    return renderer.createApp(rootComponent)
}